<template>
  <div>
    <el-container class="home-wrapper">
      <el-header>
        <div class="logo-wrap">
         
          <span>后台管理系统</span>
        </div>
        <el-button type="success" @click="tc">退出</el-button>
      </el-header>
      <el-container>
        <!-- 侧边栏 -->
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <!-- 菜单 -->
          <div class="toggle-menu" @click="isCollapse = !isCollapse">|||</div>
          <el-menu background-color="#333744" text-color="#fff" unique-opened :collapse="isCollapse" :collapse-transition="false" router>
            <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
              <template slot="title">
                <i :class="iconObj[item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item :index=" '/' + menu.path" v-for="menu in item.children" :key="menu.id">
                <template>
                  <i class="el-icon-menu"></i>
                  <span>{{ menu.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 中间内容 -->
        <el-main>
          <!-- 路由占位符 -->
           <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 侧边栏数据
      menulist: [],
       // 一级菜单图标的数据
      iconObj: {
        125: "iconfont icon-users",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      isCollapse: false,
    };
  },
  created() {
    this.getMenuList();
  },
  methods: {
    //退出功能
    tc() {
      //清除token 跳转到登录页
      sessionStorage.removeItem("token");
      this.$router.push("/index");
    },
    async getMenuList() {
      const res = await this.axios.get("/menus");
      const { data, meta } = res.data;
      if (meta.status !== 200) {
        this.$message.error(meta.msg);
      } else {
        this.menulist = data;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.home-wrapper {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #373d41;
  font-size: 22px;
  color: #fff;
  .logo-wrap {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
    img{
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
  }
}
.el-aside {
  background-color: #333744;
  .toggle-menu {
    line-height: 24px;
    background-color: #4a5064;
    font-size: 12px;
    text-align: center;
    color: #fff;
    letter-spacing: 0.02em;
    cursor: pointer;
  }
  .el-menu {
    border-right: 0;
  }
  .iconfont {
    margin-right: 10px;
  }
}

.el-main {
  background-color: #eaedf1;
}
</style>